package cn.lls.base.handler;

import cn.lls.base.exception.LlsException;
import cn.lls.base.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e) {
        e.printStackTrace();
        return R.fail(500, "网络跑飞了ne...");
    }

    @ExceptionHandler(LlsException.class)
    @ResponseBody
    public R error(LlsException e) {
        return R.fail(e.getCode(), e.getMessage());
    }
}
